package com.jajahome.util;

import android.content.Context;
import android.util.Log;

import com.jajahome.constant.Constant;
import com.jajahome.model.LoginModle;
import com.jajahome.model.PriceBasicBean;
import com.jajahome.model.PriceDiscountBean;
import com.sina.weibo.sdk.utils.LogUtil;

/**
 * 关于价格的工具类
 */
public class PriceUtil {
    private final static String ASK_PRICE = "请询价";
    private final static String VIP_ASK_PRICE = "请询价";
    private final static String QI = "起";
    private final static String DIV = " - ";
    private final static String BASIC_PRICE = "";
    public final static String VIP_FLAG = "VIP ¥";

    //在详情中显示 价格区间格式 100起
    public static String[] getItemPrice(PriceDiscountBean discountBean, PriceBasicBean basicBean) {
        String prices[] = new String[2];
        if (discountBean.getMin() == discountBean.getMax()) {//折扣价没有区间
            if (discountBean.getMin() == 0) {
                prices[0] = ASK_PRICE;
            } else {
                prices[0] = Constant.YUAN + discountBean.getMin();
                if (basicBean.getMin() != discountBean.getMin() || basicBean.getMax() != discountBean.getMax()) {
                    //价格相同没有折扣
                    if (basicBean.getMin() == basicBean.getMax()) {
                        prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin();
                    } else {
                        prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin() + DIV + basicBean.getMax();
                    }
                }
            }

        } else {
            prices[0] = Constant.YUAN + discountBean.getMin() + DIV + discountBean.getMax();
            if (basicBean.getMin() != discountBean.getMin() || basicBean.getMax() != discountBean.getMax()) {
                //价格相同没有折扣
                if (basicBean.getMin() == basicBean.getMax()) {
                    prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin();
                } else {
                    prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin() + DIV + basicBean.getMax();
                }
            }
        }
        return prices;
    }


    /**
     * 在列表中显示 价格区间格式 100起
     *
     * @param discountBean
     * @param basicBean
     * @return
     */
    public static String[] getItemPriceInList(PriceDiscountBean discountBean, PriceBasicBean basicBean) {
        String prices[] = new String[2];
        if (discountBean.getMin() == discountBean.getMax()) {//折扣价没有区间
            if (discountBean.getMin() == 0) {
                prices[0] = ASK_PRICE;
            } else {
                prices[0] = Constant.YUAN + discountBean.getMin();
                if (basicBean.getMin() != discountBean.getMin() || basicBean.getMax() != discountBean.getMax()) {
                    //价格相同没有折扣
                    if (basicBean.getMin() == basicBean.getMax()) {
                        prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin();
                    } else {
                        prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin() + QI;
                    }
                }
            }

        } else {
            prices[0] = Constant.YUAN + discountBean.getMin() + QI;
            if (basicBean.getMin() != discountBean.getMin() || basicBean.getMax() != discountBean.getMax()) {
                //价格相同没有折扣
                if (basicBean.getMin() == basicBean.getMax()) {
                    prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin();
                } else {
                    prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin() + QI;
                }
            }
        }
        return prices;
    }

    /**
     * 在列表中显示 价格区间格式 100起 (vip价格)
     *
     * @param basicBean
     * @return
     */
    public static String[] getItemVipPriceInList(float discount, PriceBasicBean basicBean) {
        String prices[] = new String[2];
        if (basicBean.getMin() == basicBean.getMax()) {//有区间
            if (basicBean.getMin() == 0) {
                prices[0] = VIP_ASK_PRICE;
            } else {
                //价格相同没有折扣
                prices[0] = VIP_FLAG + (int) (basicBean.getMin() * discount);
                prices[1] = BASIC_PRICE + Constant.YUAN + (int) (basicBean.getMin());
            }
        } else {
            prices[0] = VIP_FLAG + (int) (basicBean.getMin() * discount) + QI;
            prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin() + QI;
        }
        return prices;
    }

    /**
     * 显示价格区间
     *
     * @param discount
     * @param basicBean
     * @return
     */
    public static String[] getItemVipPriceInDetail(float discount, PriceBasicBean basicBean) {
        String prices[] = new String[2];
        if (basicBean.getMin() == basicBean.getMax()) {//有区间
            if (basicBean.getMin() == 0) {
                prices[0] = VIP_ASK_PRICE;
            } else {
                //价格相同没有折扣
                prices[0] = VIP_FLAG + (int) (basicBean.getMin() * discount);
                prices[1] = BASIC_PRICE + Constant.YUAN + (int) (basicBean.getMin());
            }
        } else {
            prices[0] = VIP_FLAG + (int) (basicBean.getMin() * discount) + DIV + (int) (basicBean.getMax() * discount);
            prices[1] = BASIC_PRICE + Constant.YUAN + basicBean.getMin() + DIV + basicBean.getMax();
        }
        return prices;
    }

    /**
     * vip价格
     *
     * @return -1/0非vip价格，大于0vip价格
     */
    public static float getVipPrice(Context context) {
        if (!LoginUtil.isLogin(context)) {
            return 0;
        }
        LoginModle info = LoginUtil.getInfo(context);

        if (info != null && info.getData() != null) {
            LoginModle.DataBean.UserBean user = info.getData().getUser();
            if (!getShowVipPrice(context, user.getId())) {
                return 0;
            }
            // //1 注册用户(一般用户), 2 设计师(申请中), 3 认证设计师(审核通过), 4装饰公司,5 城市合伙人,6协会
            String type = user.getType();
            if (type.equals("3") || type.equals("4") || type.equals("5")) {
                return user.getDiscount_rate();
            }
        }
        return 0;
    }

    private static boolean getShowVipPrice(Context context, String id) {
        boolean isShowVip = (boolean) SPUtils.get(context, "SHOW_VIP_PRICE" + id, false);
        Log.e("isShowVip:", id + isShowVip + "");
        return isShowVip;
    }
}
